package com.rms.hkpc.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.rms.hkpc.MyApplication;

public class SPUtil {
    private static volatile SPUtil instance;
    private SharedPreferences share;
    private SharedPreferences.Editor editor;
    private final String SHARED_NAME = "HKPC";

    public SPUtil() {
        share = MyApplication.getContext().getSharedPreferences(SHARED_NAME, Context.MODE_PRIVATE);
        editor = share.edit();
    }

    public static SPUtil getInstance() {
        if (instance == null) {
            synchronized (SPUtil.class) {
                if (instance == null) {
                    instance = new SPUtil();
                }
            }
        }
        return instance;
    }

    public void putString(String spName, String value) {
        editor.putString(spName, value);
        editor.commit();
    }

    public String getString(String spName) {
        return share.getString(spName, "");
    }

    public void putInt(String spName,int value){
        editor.putInt(spName,value);
        editor.commit();
    }

    public int getInt(String spName,int defaultValue){
        return share.getInt(spName,defaultValue);
    }

}
